<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<body>
    <script>
        let num = 1000000000;
        function thousansFormat(num)
        {
            let str = num.toString()
            
            let result ="";
            let count = 0;
            for(let i = str.length-1;i>=0;i--)
            {
                result = +str[i]+result;
                count++;
                if(count%3===0&&i!=0)
                {
                    result = ','+result;
                }
            }
            return result;
        }

        let result = thousansFormat(num);
        console.log(result);
    </script>
</body>
</html>